package com.czk.controller;

import com.czk.pojo.Calculation;
import com.czk.pojo.CreditCardApplyInfo;
import com.czk.service.RuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/8/24 22:42
 */
@RestController
@RequestMapping("/rule")
public class RuleController {
    @Autowired
    private RuleService ruleService;

    @GetMapping("/fire")
    public String rule() {
        ruleService.rule();
        return "调用成功";
    }

    @GetMapping("/calculate/{wage}")
    public Calculation calculate(@PathVariable("wage") Double wage) {
        Calculation calculation = new Calculation();
        calculation.setWage(wage);
        Calculation calculate = ruleService.calculate(calculation);
        System.out.println(calculate);
        return calculate;
    }

    @GetMapping("/credit/{education}/{hasCar}/{hasHouse}/{income}")
    public CreditCardApplyInfo cardApplyInfo(@PathVariable("education") String education,
                                             @PathVariable("hasCar") boolean hasCar,
                                             @PathVariable("hasHouse") boolean hasHouse,
                                             @PathVariable("income") Double income) {
        CreditCardApplyInfo creditCardApplyInfo = new CreditCardApplyInfo();
        creditCardApplyInfo.setEducation(education);
        creditCardApplyInfo.setHasCar(hasCar);
        creditCardApplyInfo.setHasHouse(hasHouse);
        creditCardApplyInfo.setMonthlyIncome(income);
        return ruleService.cardApplyInfo(creditCardApplyInfo);
    }
}
